home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
nortutil.zip
/
src
/
NewSpeak
/
newspeak.x
Wrap
Text File
|
1994-04-13
|
20KB
|
675 lines
%{ -*- Mode:Fundamental -*-
/*
* newspeak.l
* Lex filter to transform plain English into NewSpeak.
* Copyright (c) 1991 Jamie Zawinski <jwz@lucid.com>.
* Permission granted for noncommercial use and redistribution.
*
* To compile:
*
* flex newspeak.l
* cc -O -o newspeak lex.yy.c
* rm lex.yy.c
*
* This must be compiled with "flex", not normal "lex". Lex has
* some builtin, unchangable limits which this program exceeds.
* This has been verified to work with flex version 2.3.7, and
* may not work with flex version 2.3.6.
*
* You can get 'flex' by anonymous FTP to prep.ai.mit.edu, or
* anywhere else you get GNU software.
*
* Run this like so: "newspeak < some-text-file | more"
*
* There are some design notes near the end. Suggestions and
* improvements to this code are more than welcome.
* Hail Big Brother!
*---------------------------------------------------------------------------
*/
#include <stdio.h>
unsigned int fcounter = 0;
#define Y0 yytext[0]
#define Y1 yytext[1]
#define Y2 yytext[2]
#define Y3 yytext[3]
#define C caseify
#define C1 caseify1
#define CAP(string) capstring(0, (string),0)
#define WCAP(string) capstring(Y0,(string),1)
#define COMP(string1,string2) compstring(0, (string1),(string2),0)
#define WCOMP(string1,string2) compstring(Y0,(string1),(string2),1)
#define DUMP() printf("%s",yytext)
%}
%e 8000
%p 9000
%n 2000
%k 3000
%a 5000
%o 4000
W (([ ]?\n[ ]*)|[ ]|[\"'`])
ES [.,;:!?/]
EW ({W}|{ES}|"'")
YOUNG (([Yy]oung|[Ss]mall|[Ll]ittle){W})
DEAD (([Dd]ead|[Dd]eceased){W})
THE ([Tt]he{W}?)
ANDOR ({W}(([Aa]nd)|([Oo]r)){W}?)
COLOR (red|green|blue|yellow|cyan|magenta|purple|orange|mauve|pink|turquoise|brown|gr[ae]y)
%%
%{
/******************************
* PLUSwords *
******************************/
%}
[Qq]uite{EW}/[A-Za-z][A-Za-z] CAP("plus");
[Rr]ather{EW}/[A-Za-z][A-Za-z][A-Za-z] CAP("plus");
[Kk]ind{EW}of{EW}/[A-Za-z][A-Za-z][A-Za-z] CAP("plus");
[Kk]inda{EW}/[A-Za-z][A-Za-z][A-Za-z] CAP("plus");
[Mm]ore{W}than{W}a{W}(little|bit){W} CAP("plus");
[Pp]ro- CAP("plus");
[Hh]undreds{W}of{W}[Tt]housands |
[Hh]undreds{ANDOR}[Tt]housands |
[Hh]undreds{W}if{W}not{W}[Tt]housands |
[Tt]housands |
[Mm]illions CAP("doubleplusmany");
[Dd]ozens CAP("many");
[Hh]undreds CAP("plusmany");
([Bb]right|[Ll]ight|[Ii]ntense){W}/{COLOR} CAP("plus");
([Dd]im|[Ff]aded|[Dd]ark|[Pp]ale){W}/{COLOR} CAP("plusun");
[Ee]very DUMP();
[Vv]ery{W} |
[Rr]eally{W} |
[Tt]erribly{W} |
[Aa]wesome({W})? |
[Aa]wfully{W} CAP("doubleplus");
[Ww]hopping{EW} CAP("plusbig");
"O.K." |
[Aa]ll({W})?[Rr]ight |
[Oo][Kk][Aa][Yy] CAP("plusgood");
{W}OK/{W} WCAP("plusgood");
([Tt]oo|[Oo]verly|[Tt]hat){W}[Mm]uch CAP("plusmuch");
{W}[Bb]ad/{EW} WCAP("ungood");
{W}[Pp]oor/{EW} WCAP("ungood");
{W}[Ll]ame/{EW} WCAP("ungood");
{W}[Pp]itiful/{EW} WCAP("ungood");
{W}[Nn]asty/{EW} WCAP("plusungood");
{W}[Hh]orrid/{EW} WCAP("doubleplus ungood");
{W}[Hh]orrible/{EW} WCAP("doubleplus ungood");
{W}[Aa]wful/{W} WCAP("doubleplus ungood");
{W}[Ee]vil/{W} WCAP("doubleplus ungood");
%{
/******************************
* Titles *
******************************/
%}
{W}[Ss]ir/{EW} WCAP("citizen");
{W}[Mm]r"."/{EW} WCAP("brother");
[Mm]ister/{EW} CAP("brother");
[Mm]adame? CAP("sister");
{W}[Mm]iss/{EW} WCAP("sister");
[Mm]a"'"?am/{EW} CAP("sister");
{W}[Mm]r?s"."/{EW} WCAP("sister");
Mrs/{EW} CAP("sister");
{YOUNG}?[Cc]hildren CAP("young citizens");
{YOUNG}?[Bb]oys{ANDOR}[Gg]irl/s CAP("young citizens");
{YOUNG}?([Kk]id|[Gg]irl|[Bb]oy|[Cc]hild)/{EW} CAP("young citizen");
[Ff]ellow CAP("citizen");
[Nn]on{W}?"-"?citizen CAP("unperson");
[Nn]on{W}?"-"?member CAP("unperson");
[Cc]riminal/s? CAP("unperson");
{DEAD}(man|woman) CAP("unperson");
{DEAD}(men|women) CAP("unpersons");
[Ii]n{W}[Pp]erson DUMP();
{W}[Uu]ser WCOMP("party ","worker");
[Ss]tudent COMP("party ","worker");
[Cc]itizen/s?{EW} COMP("party ","worker");
[Pp]erson/s?{EW} COMP("party ","worker");
[Pp]eople COMP("party ","workers");
[Ss]enator |
[Cc]ongressman |
[Ss]upervisor |
[Pp]rofessor printf("Inner Party Member");
[Pp]rof"."/{EW} printf("Inner Party Member");
[Pp]rof/{EW} printf("Inner Party Member");
Representative/s? printf("Inner Party Member");
representatives printf("Inner Party Members");
[Ww]hite{W}[Cc]ollar |
[Uu]pper{W}[Cc]lass COMP("inner ","party");
[Mm]iddle{W}[Cc]lass CAP("party");
[Bb]lue{W}[Cc]ollar |
[Ww]orking{W}[Cc]lass |
[Ll]ower{W}[Cc]lass CAP("prole");
([Ff]ool|[Ii]diot)/s?{EW} CAP("prole");
[Ss]tupidity CAP("proleness");
%{
/******************************
* Organizations *
******************************/
%}
[Aa]?{W}([Ww]hite{W}[Hh]ouse|[Gg]ovt\.?|[Gg]overnment){W}([Ss]ource|[Oo]fficial|[Ss]pokes(man|woman|person)) CAP("an Inner Party Member");
{THE}?[Rr]epublican{W}[Pp]arty COMP("mini","luv");
{THE}?[Dd]emocratic{W}[Pp]arty COMP("mini","plenty");
{THE}?Congress printf("MiniPax");
{THE}?[Ss]enate printf("MiniPax");
{THE}?[Hh]ouse{W}[Oo]f{W}[Rr]epresentatives printf("MiniPax");
{THE}?[Ss]tate{W}[Dd]epartment printf("MiniPax");
{THE}?[Ss]tate{W}[Dd]ept"."? printf("MiniPax");
{THE}?[Dd]efen[cs]e{W}[Dd]epartment |
{THE}?[Dd]efen[cs]e{W}[Dd]ept"."? |
{THE}?[Ww]ar{W}[Dd]epartment |
{THE}?[Ww]ar{W}[Dd]ept"."? |
{THE}?[Hh]ouse{W}of{W}[Cc]ommons |
{THE}?Pentagon |
{THE}?[Ff]eds |
{THE}?FCC |
{THE}?D[Oo]D |
{THE}"D."[Oo]".D." |
{THE}?[Ss]ecret{W}[Ss]ervice COMP("mini","luv");
{THE}?White{W}House |
{THE}?Kremlin printf("MiniTrue");
{THE}?(CIA|NSA|FBI|MI"-"?5)/{EW} printf("MiniTrue");
{THE}?("C.I.A."|"N.S.A."|"F.B.I.")/{EW} printf("MiniTrue");
{THE}?[Aa]rchive/s? COMP("mini","rec");
{THE}?[Ll]ibrary COMP("mini","rec");
{THE}?[Ll]ibraries COMP("mini","recs");
[Tt]hought{W}[Pp]olice|[Nn]azis? COMP("think","pol");
[Vv]ice{W}[Ss]quad COMP("sex","pol");
PMRC|"P.M.R.C." COMP("sex","pol");
[Oo]fficer CAP("minister");
{THE}?[Dd]epartment{EW}of{EW}. |
{THE}?[Dd]ept"."?{EW}of{EW}. |
{THE}?[Uu]niversity{EW}of{EW}. |
{THE}?[Uu]niv"."?{EW}of{EW}. |
{THE}?[Dd]ept"."?{EW}of{EW}. |
{THE}?([Ss]ub"-"?)?[Cc]omm?itt?ee{EW}(of|on){EW}. |
{THE}?[Ss]chool{EW}of{EW}. {
if ((yytext[yyleng-1] >= 'A') && (yytext[yyleng-1] <= 'Z'))
/* "the school of Law" --> "MiniLaw" */
printf("Mini%c",yytext[yyleng-1]);
else if ((yytext[yyleng-1] >= 'a') && (yytext[yyleng-1] <= 'z'))
/* "the school of law" --> "MiniLaw" (not "Minilaw") */
printf("Mini%c",yytext[yyleng-1] - ('a' - 'A'));
/* "the school of 5 things" --> "Ministry of 5 things" */
else printf("Ministry of %c",yytext[yyleng-1]);
}
[Dd]epartment |
[Uu]niversity CAP("ministry");
[Uu]niv"."?/{W} CAP("ministry");
[Dd]ept"."?/{W} CAP("ministry");
([Ss]ub"-"?)?[Cc]omm?itt?ee CAP("ministry");
{THE}[Pp]roject/{EW} CAP("the Three Year Plan");
[Oo]ur{W}[Pp]roject/{EW} CAP("our Three Year Plan");
[Bb]udget printf("Three Year Plan");
[Pp]roject/{ES} printf("Three Year Plan");
{W}({THE}|([aa]{W}))[Pp]roject printf("%cthe Three Year Plan",Y0);
[A-Za-z]+"'"[Ss]/{W}(law|Law|LAW|book|Book|BOOK|rule|Rule|RULE){EW} printf("Goldstein's");
%{
/******************************
* Actions *
******************************/
%}
[Ii]n{W}love{EW} CAP("commiting SexCrime");
[Ll]ove{W}you/{EW} CAP("love Big Brother");
[Ll]ove{W}me/{EW} CAP("love Big Brother");
[Cc]loning |
[Rr]eproduction |
[Cc]elibacy |
[Pp]rocreation COMP("good","sex");
[Cc]elibate |
[Pp]rocreate COMP("good","sexwise");
[Tt]elevisions? |
TVs? |
[Tt]"."[Vv]"."s? |
[Rr]adios? |
[Nn]ews{W}?[Pp]apers? |
[Jj]ournalism |
[Mm]ovies? |
[Rr]ock{EW}?"-"?(and|"&"|"'"?n"'"?){EW}?"-"?[Rr]oll({W}[Mm]usic)? |
(([Rr]ock|[Cc]lassical|[Ii]ndustrial|[Pp]op|[Dd]ance|[Rr]ap){W})?[Mm]usic |
[Tt]unes |
[Mm]oney |
[Cc]ash |
[Cc]omic{W}[Bb]ooks? |
([Ss]tar{W}?)?[Tt]rek COMP("prole","feed");
[Pp]eace{W}[Mm]ovement |
[Pp]eace{W}[Pp]rotest |
[Aa]nti{EW}[Ww]ar |
([Pp]assive{W})?[Rr]esistance |
[Cc]reativity |
[Tt]reason |
[Rr]esearch COMP("crime","think");
%{
/******************************
* Religion